<template>
  <el-dialog :title="title" :visible="visible" @close="closeFn" @open="openFn">
    <el-form
    label="right"
     :model="formIn" label-width="140px" ref="form" :rules="rules">
      <el-form-item prop="name" label="合作商名称" >
        <el-input
          v-model="formIn.name"
          autocomplete="off"
          placeholder="请输入"
           style="width: 396px"
        ></el-input>
      </el-form-item>
      <el-form-item label="联系人"
      prop="contact"
      >
        <el-input
          v-model="formIn.contact"
          autocomplete="off"
          placeholder="请输入"
           style="width: 396px"
        ></el-input>
      </el-form-item>
           <el-form-item label="联系电话"
           prop="mobile">
        <el-input
          v-model="formIn.mobile"
          autocomplete="off"
          placeholder="请输入"
           style="width: 396px"
        ></el-input>
      </el-form-item>
           <el-form-item label="成分比例(%)" prop="ratio" >
        <el-input-number controls-position="right"
           style="width: 396px"
           @change="handleChange"
          placeholder="请输入"
          v-model='formIn.ratio'
            :min="1"></el-input-number>
      </el-form-item>
            <el-form-item>
        <el-row type="flex" justify="start" align="center">
          <el-col :span="18">
            <el-button class="closeFn" @click="closeFn">取 消</el-button>
            <el-button
              style="margin-left: 20px"
              class="comfirm"
              @click="confirmFn"
              >确 定</el-button
            >
          </el-col>
        </el-row>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { editPainner } from '@/api/point'
export default {
  props: {
    visible: Boolean,
    rows: {
      type: [Array, Object],
      default: () => {}
    },
    or: {
      type: Number,
      default: 1
    },
    queryParams: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      title: '修改合作商',
      formIn: {
        account: '',
        contact: '',
        mobile: '',
        name: '',
        ratio: null
      },
      rules: {
        name: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        account: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        contact: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        mobile: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        ratio: [
          { required: true, message: '请输入', trigger: 'change' }
        ]
      }

    }
  },
  created () {

  },
  methods: {
    handleChange () {
      // console.log(val)
    },
    openFn () {
      if (this.or === 2) {
        const obj = JSON.parse(JSON.stringify(this.rows))
        //   console.log(obj === this.rows)
        this.formIn = obj
      }
      console.log('or:编辑', this.formIn.id)
    },
    closeFn () {
      this.$refs.form.resetFields()
      this.$emit('update:visible', false)
    },
    async confirmFn () {
      if (this.or === 2) {
        try {
          const res = await editPainner({ ...this.formIn })
          console.log(res)
          this.$message.success('修改成功')
          this.closeFn()
          // this.$router.push('/partner')
          this.getPointListFn()
        } catch (error) {
          this.$message.error(error.response.data)
        }
      }
    }
  },
  inject: ['getPointListFn']
}
</script>

<style lang="less" scoped>
/deep/ .el-dialog {
  width: 630px;
  border-radius: 15px;
}
/deep/ .el-dialog__header {
  padding: 20px 20px 10px;
  text-align: left;
  font-weight: 700;
  font-size: 16px;
}
/deep/ .el-dialog__body {
  padding: 20px 20px;
}
.cancel {
  width: 80px;
  height: 36px;
  color: #655b56 !important;
  background-color: antiquewhite;
  border: none;
}
.comfirm {
  width: 80px;
  height: 36px;
  color: #fff;
  background: linear-gradient(135deg, #ff9743, #ff5e20) !important;
  border: none;
}
</style>
